package chapter07

/**
 * 多维数组
 */
object Test03_MulArray {
  def main(args: Array[String]): Unit = {
    //1、创建多维数组
    val array: Array[Array[Int]] = Array.ofDim[Int](2, 3)

    //2、访问元素
    array(0)(2) = 19
    array(1)(0) = 25

    println(array.mkString(","))

    println("-------简写一----------------")
    for (i <- 0 until array.length; j <- 0 until array(i).length) {
      println(array(i)(j))
    }


    println("-------循环二----------------")

    for (i <- array.indices; j <- array(i).indices) {
      println(array(i)(j) + "\t")
      if (j == array(i).length - 1) println()
    }

    println("-------简写----------------")
    array.foreach(line => line.foreach(println))

    //简写 _代替
    println("-------_代替简写----------------")
    array.foreach(_.foreach(println))

  }
}
